//
//  ChongZhiViewController.m
//  ShangChengMoBan
//
//  Created by yaoqi yaoqi on 16/9/13.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "ChongZhiViewController.h"
#import "DengLuViewController.h"
@interface ChongZhiViewController ()<UIAlertViewDelegate>

@end

@implementation ChongZhiViewController
{
    UITextField * _miMa, * _miMa2;
    UIButton * _button;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawNavWithTitle:@"重置密码" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
     self.view.backgroundColor = [UIColor colorWithHue:0.69 saturation:0.02 brightness:0.96 alpha:1.00];
    [self drawBackButton];
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 35+64, KScreenWidth, 40)];
    view.layer.borderWidth = 1 ;
    view.layer.borderColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00].CGColor;
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    _miMa = [[UITextField alloc]initWithFrame:CGRectMake(15, 5, KScreenWidth-15, 30)];
    _miMa.placeholder = @"请重置一个密码,最少6位";
    _miMa.font = [UIFont systemFontOfSize:13];
    [_miMa setSecureTextEntry:YES];
    [view addSubview:_miMa];
    UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, view.bottom+1, KScreenWidth, 40)];
    view2.layer.borderWidth = 1 ;
    view2.layer.borderColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00].CGColor;
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    _miMa2 = [[UITextField alloc]initWithFrame:CGRectMake(15, 5, KScreenWidth-15, 30)];
    _miMa2.placeholder = @"请再次输入密码";
    _miMa2.font = [UIFont systemFontOfSize:13];
    [_miMa2 setSecureTextEntry:YES];
    [view2 addSubview:_miMa2];
   
    _button = [[UIButton alloc]initWithFrame:CGRectMake(10, view2.bottom+10, 20, 20)];
    [_button setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    _button.selected = NO;
     [_button setBackgroundImage:[UIImage imageNamed:@"未选择 (1)"] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(take) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_button];
    UILabel * tit = [[UILabel alloc]initWithFrame:CGRectMake(_button.right+5, view2.bottom+10, KScreenWidth-50, 20)];
    tit.text = @"显示密码";
    tit.textColor = MaintextColor;
    tit.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:tit];
    UIButton * xiaBu = [[UIButton alloc]initWithFrame:CGRectMake(20, _button.bottom+50, KScreenWidth-40, 35)];
    [xiaBu setTitle:@"完成" forState:UIControlStateNormal];
    xiaBu.titleLabel.font = [UIFont systemFontOfSize:14];
    xiaBu.backgroundColor = [UIColor colorWithHue:1.00 saturation:1.00 brightness:1.00 alpha:1.00];
    [xiaBu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    xiaBu.layer.cornerRadius = 4;
    [xiaBu addTarget:self action:@selector(wanCheng) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:xiaBu];
}
#pragma mark 完成重置
-(void)wanCheng{
    [_dic setObject:_miMa.text forKey:@"newPassword"];
    [_dic setObject:_miMa2.text forKey:@"rPassword"];
   [NetWorking NEWjieKouQingQiu:WJ_userZhaoHuiMiMa ANDIP:IP And:_dic anBlock:^(NSDictionary *dic, NSError *error) {
       if (!error) {
           if ([dic[Code] intValue] == 200) {
                [TCUtils showAlertViewWithTitle:@"提示" message:@"密码重置成功" delegate:self cancel:@"确定" other:nil tag:777];
            }
       }
   }];
}
#pragma mark 显示密码
-(void)take{
    _button.selected = !_button.selected;
    _miMa.secureTextEntry = !_miMa.secureTextEntry;
    _miMa2.secureTextEntry = !_miMa2.secureTextEntry;
     if (_button.selected) {
        [_button setBackgroundImage:[UIImage imageNamed:@"对勾-1"] forState:UIControlStateNormal];
    }else{
    [_button setBackgroundImage:[UIImage imageNamed:@"未选择 (1)"] forState:UIControlStateNormal];
     }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        DengLuViewController * deng = [[DengLuViewController alloc]init];
        [self.navigationController pushViewController:deng animated:YES];
    }
  
}

@end
